package com.snake.springboot.custom.service.assemble.fileoss;


import com.snake.springboot.custom.api.model.fileoss.FileOSSModel;
import com.snake.springboot.custom.api.model.fileoss.OSSPoliciesModel;
import com.snake.springboot.custom.api.response.fileoss.OSSPoliciesRsp;
import com.snake.springboot.custom.dao.mybatis.entity.fileoss.FileRecordDO;
import com.snake.springboot.custom.service.config.Properties;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.exception.OperationException;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>文件记录组装器
 * 类{@code FileRecordAssemble} </br>
 * 创建时间2025/5/8 17:55
 *
 * @author yangxt
 * @see
 */
public class FileRecordAssemble {
    public static FileRecordDO toRecordDO( FileOSSModel ossModel, OSSPoliciesModel model) {
        OperationException.checkNotNull(ossModel,"文件文件服务器不存在");
        String format = new SimpleDateFormat("yyyyMM").format(new Date());
        int fileIndex = model.getFileName().lastIndexOf(".")+1;
        String ges = model.getFileName().substring(fileIndex);
        String dir=String.format(Properties.fileDir,model.getCustomId(),model.getModule(),format,ges,
                SerialNumberGeneratorFactory.buildId4Bean()+model.getFileName().substring(fileIndex-1));
        FileRecordDO recordDO = new FileRecordDO();
        recordDO.setCustomId(model.getCustomId());
        recordDO.setFileRecordId(SerialNumberGeneratorFactory.buildId4Bean());
        recordDO.setFileName(model.getFileName());
        recordDO.setFileOssId(ossModel.getFileOssId());
        recordDO.setFileUrl(dir);
        recordDO.setFileSize(model.getFileSize());
        return recordDO;
    }

}
